<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./src/react.js"></script>
    <script src="./src//react-dom.js"></script>
    <script src="./src//babel.js"></script>
</head>
<body>
    <div id="app"></div>
</body>
</html>
<script type="text/babel">
class Title extends React.Component{
    constructor(){
        super()
        this.state={
            num:0
        }
        console.log(this);
    }
    componentDidMount(){
        // 只执行一次刚进页面触发
        console.log("组件已经挂载到视图--执行一次")
    }
    componentDidUpdate(){
        // 数据一更新就会改变
        console.log("组件已更新 -- state props 更新后 就会执行")
    }
    componentWillUnmount(){
        console.log("组件将要销毁-- 执行一次")
    }
    btn=()=>{
       let a =  this.state.num+=1
       console.log(a);
       this.setState({
            num:a
        })
    }
    render(){
         // 数据一更新就会改变
        console.log("render渲染函数 -- state props 更新后 就会执行")
        return <div>
            <h2>{this.state.num}</h2>
            <button onClick={this.btn}>+</button></div>
    }

}
ReactDOM.render(
    <Title></Title>,
    document.getElementById('app')
)
</script>